﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DevelopTools.UI
{
    /// <summary>
    /// 旋转组件
    /// </summary>
    public class RotateObject : MonoBehaviour
    {
        /// <summary>
        /// 旋转速度
        /// </summary>
        public float speed = 10;
        /// <summary>
        /// 旋转中心物体
        /// </summary>
        public GameObject centerObj;
        /// <summary>
        /// 旋转方向 顺时针 1;逆时针 -1
        /// </summary>
        public int dirSpeed = 1;

        // Use this for initialization
        void Start()
        {
            Init();
        }

        // Update is called once per frame
        void Update()
        {
            Rotate(this.transform);
        }

        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {
            if (centerObj == null)
                centerObj.transform.parent = transform;
            centerObj.transform.localPosition = Vector3.zero;
            GetComponent<Renderer>().enabled = false;
        }

        /// <summary>
        /// 旋转
        /// </summary>
        /// <param name="targetObject">旋转的物体中心</param>
        public void Rotate(Transform targetObject)
        {
            if (UIStateControl.instance.mStateCarr == UIStateControl.StateCarR.RotateObject)
            {
                targetObject.Rotate(Vector3.up, Time.deltaTime * speed);
            }

        }
    }
}